<html>
<head>
    <title>获取音视频设备数据</title>
    <meta charset="utf-8"/>
</head>
<body>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script>
    /*if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
        console.log('getUserMedia is not supported');
    } else {
        var contraints = {
            audio: true,
            video: {
                width: 1280,
                height: 720,
                frameRate: { min: 10, ideal: 20 }
            }
        };
        navigator.mediaDevices.getUserMedia(contraints)
            .then(stream => {
                stream.getTracks().forEach(track => {
                    console.log(`id ${track.id}, kind: ${track.kind}, label: ${track.label}`);
                    console.log(JSON.stringify(track.getConstraints()));
                    console.log(JSON.stringify(track.getSettings()));
                });
            }).catch(err => {
            console.log('getUserMedia failed, ', err);
        });
    }*/

    async function Start() {
        if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
            console.log('getUserMedia is not supported');
        } else {
            var pcAmy = new RTCPeerConnection();
            var pcBob = new RTCPeerConnection();

            var contraints = {
                audio: true,
                video: true
            };
            var stream = await navigator.mediaDevices.getUserMedia(contraints);
            stream.getTracks().forEach(track => {
                pcAmy.addTrack(track);
                pcBob.addTrack(track);
            });

            var offerSdp = await pcAmy.createOffer();
            await pcAmy.setLocalDescription(offerSdp);

            // offerSdp通过信令发送给Bob

            await pcBob.setRemoteDescription(offerSdp);
            var answerSdp = await pcBob.createAnswer();
            await pcBob.setLocalDescription(answerSdp);

            // answerSdp通过信令发送给Amy

            await pcAmy.setRemoteDescription(answerSdp);

            console.log(pcAmy.localDescription);  //A的sdp
            console.log(pcAmy.remoteDescription);

            console.log(pcBob.localDescription); //B的sdp
            console.log(pcBob.remoteDescription);
        }
    }

    Start();
</script>
</body>
</html>